﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Quizzer.Model;

namespace Quizzer.DataAccess
{
    public static class QuestionResultRepository
    {
        readonly static Dictionary<Guid, QuestionResult> _questionResults;

        static QuestionResultRepository()
        {
            _questionResults = LoadQuestionResults();
        }

        static Dictionary<Guid, QuestionResult> LoadQuestionResults()
        {
            return QuestionResult.Items;
        }

        public static void Add(QuestionResult qr)
        {
            _questionResults.Add(qr.Id, qr);
        }

        public static ObservableCollection<QuestionResult> GetQuestionResults(Attempt attempt)
        {
            var query = from questionResult in _questionResults.Values
                        where questionResult.AttemptID == attempt.Id
                        select questionResult;

            return new ObservableCollection<QuestionResult>(query.ToList());
        }

    }
}
